package com.cmcc.volte.xdr.util;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StyleConversionUtils {
	
	public static Map<String,String> styleConversion(Map<String,String> map){
		Map<String, String> mapData = new LinkedHashMap<String, String>();
		for(Map.Entry<String, String> entry : map.entrySet()){
			List<String> listData = new ArrayList<String>();
			String content = entry.getValue();
			String regex = "(?<=<br>)[A-Z].+?(?=:)";
	        Pattern p = Pattern.compile(regex);
	        Matcher m = p.matcher(content);
	        while(m.find()) {
	        	listData.add(m.group(0));
	        }
	        for (String str : listData) {
				String styleStr = "<font size=\"3\"><strong>"+str+"</strong></font>";
				content = content.replace(str, styleStr);
			}
	        String regex1 = "^[A-Z]{2,15}\\s+";
			Pattern p1 = Pattern.compile(regex1);
			Matcher m1 = p1.matcher(content);
			if(m1.find()) {
				String con = m1.group(0);
				content = content.replace(con, "<font size=\"3\"><strong>"+con+"</strong></font>");
			}
			String regex2 = "^[A-Z][a-z]{2,15}(?=:)";
			Pattern p2 = Pattern.compile(regex2);
			Matcher m2 = p2.matcher(content);
			if(m2.find()) {
				String con = m2.group(0);
				content = content.replace(con, "<font size=\"3\"><strong>"+con+"</strong></font>");
			}
	        mapData.put(entry.getKey(), content);
		}
		return mapData;
	}
}
